<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/laydate/laydate.js}"></script>
  <script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<style type="text/css">
  #birthday{
    padding-right: 0;
    height: 32px;
    line-height: 32px;
  }
</style>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="userList.html">系统管理</a></li>
    <li><a href="userList.html">用户管理</a></li>
    <li><a href="#">修改</a></li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>员工信息</span></div>
  <ul class="forminfo">
    <li>
      <label>员工编号</label>
      <input name="uId" type="text" th:value="${user.uId}" class="dfinput" />
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>员工姓名</label>
      <input name="uname" type="text" th:value="${user.uname}" class="dfinput" />
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>密码</label>
      <input name="upassword" type="password" th:value="${user.upassword}" class="dfinput" />
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>性别</label>
      <cite >
          <input name="sex" type="radio" value="1"  th:attr="checked=${user.sex=='1'?true:false}" />男
          &nbsp;&nbsp;&nbsp;&nbsp;
          <input name="sex" type="radio"   value="2" th:attr="checked=${user.sex=='2'?true:false}" />女
      </cite>
    </li>
    <li>
      <label>联系方式</label>
      <input name="utelephone" type="text" th:value="${user.utelephone}" class="dfinput" />
      <i>必填，不能超过30个字符</i>
    </li>
    <li>
      <label>出生年月</label>
      <input name="birthday" class="dfinput laydate-icon" id="birthday" th:value="${#dates.format(user.birthday,'yyyy-MM-dd')}">
    </li>
    <li>
      <label>所属部门</label>
      <select name="deptName" class="dfselect">
        <option th:each="sysdept : ${byDept}" th:text="${sysdept.deptName}"></option>
      </select>
    </li>
    <li>
      <label>职位</label>
      <select name="jobName" class="dfselect">
        <option  th:each="sysjob : ${byJob}" th:text="${sysjob.jobName}"></option>
      </select>
    </li>
    <li>
      <label>状态</label>
      <select name="statusId" class="dfselect">
        <option th:each="sta : ${user}" th:text="${sta.statusId=='1'?'在职':'不在职'}"></option>
        <option th:each="sta : ${user}" th:text="${sta.statusId=='2'?'在职':'不在职'}"></option>
      </select>
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="usp" type="button" class="btn" value="确认保存"/>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="" type="button" class="btn" value="返回"  onclick="window.history.go(-1);"/>
    </li>
  </ul>
</div>
<script type="text/javascript">
  !function(){
    laydate.skin('molv');//切换皮肤，请查看skins下面皮肤库
    laydate({elem: '#birthday'});//绑定元素
  }();

  $(function (){

    $("input[name='usp']").click(function () {
      let data={"uId":$("input[name='uId']").val(),
        "uname":$("input[name='uname']").val(),
        "upassword":$("input[name='upassword']").val(),
        "sex":$("input[name='sex']:checked").val(),
        "utelephone":$("input[name='utelephone']").val(),
        "birthday":$("input[name='birthday']").val(),
        "deptName":$("select[name='deptName']>option:selected").val(),
        "jobName":$("select[name='jobName']>option:selected").val(),
        "statusId":$("select[name='statusId']>option:selected").val()

      }
      $.ajax({
          url:"/sys/updateUser",
          data:data,
          type:"POST",
          resultType:"JSON",
          success:function (result) {
            if(result<0){
              alert("保存失败")
            }else {
              alert("保存成功");
              location.href="/sys/userList";
            }
          }
      });
    })

  })

  $("select[name='deptName']").change(function () {
	  let deptName = $(this).find("option:selected").val();
	  alert(deptName);
	  $.ajax({
		  url:"/sys/getJob",
		  type: "POST",
		  data: {"deptName": deptName},
		  dataType: "JSON",
		  success:function (result) {
			  if (result != null) {
				  let parse = JSON.parse(result);
				  let ops = "";
				  for (let i in parse) {
					  ops+="<option>"+parse[i].jobName+"</option>"
				  }
				  $("select[name='jobName']").html(ops);
			  }
		  }
	  })
  })
</script>
</body>
</html>
